package com.fairytask.ui.room
{
	import com.fairytask.data.ViewObject;
	import com.fairytask.define.ViewDefine;
	import com.fairytask.net.NetSocket;
	import com.fairytask.tools.CommonTools;
	import com.fairytask.ui.base.FrameUI;
	import com.greensock.events.LoaderEvent;
	import com.greensock.loading.LoaderMax;
	import com.greensock.loading.SWFLoader;
	import com.smartfoxserver.v2.entities.SFSRoom;
	
	import flash.display.MovieClip;

	/**
	 * 房间列表 
	 * @author game
	 * 
	 */	
	public class RoomListUI extends FrameUI
	{
		private static var _instance	:RoomListUI;
		private var hallMc:*;
		[Bindable]
		private var roomList:Array;
		
		private var loaderMax	:LoaderMax;
		private var listMc:MovieClip;
		
		public static function get instance():RoomListUI
		{
			if(null==_instance)
			{
				_instance	=	new RoomListUI();
			}
			return _instance;
		}
		
		public function RoomListUI(popUI:Boolean=false)
		{
			super(popUI);
			initBind();
		}
		
		override public function initGUI():void
		{
			super.initGUI();
			
			loaderMax	=	new LoaderMax();
			loaderMax.addEventListener(LoaderEvent.COMPLETE,onLoaded);
			
			loaderMax.append(new SWFLoader("res/ui/profile.swf",{name:"profile",context:CommonTools.context}));
			loaderMax.append(new SWFLoader("res/ui/roomList.swf",{name:"roomList",context:CommonTools.context}));
			loaderMax.load();
		}
		
		protected function onLoaded(event:LoaderEvent):void
		{
			hallMc	=	CommonTools.getMcByName(loaderMax,"profile","com.fairytask.ui.profile",windowBG);
			hallMc.tfNickName.text	=	"幻娱网络";
			
			//显示房间列表
			listMc	=	CommonTools.getMcByName(loaderMax,"roomList","com.fairytask.ui.roomList",windowBG);
			listMc.x	=	260;
		}
		
		/**
		 * 数据绑定 
		 */
		private function initBind():void
		{
			bindManager.BindView(model.scene,ViewDefine.ROOM,onRoomAdd,onRoomRemove);
		}
		
		/**
		 * 删除房间 
		 * @param pKey
		 * @param pVal
		 * 
		 */
		private function onRoomRemove(pKey:String,pVal:ViewObject):void
		{
			
		}
		
		/**
		 * 添加房间 
		 * @param pKey
		 * @param pVal
		 * 
		 */
		private function onRoomAdd(pKey:String,pVal:ViewObject):void
		{
			
		}
		
		/**
		 * 重写显示在区域 
		 * @param space
		 * @param onshow
		 * 
		 */
		override public function show(space:String=BACKLAYER, onshow:Function=null):void
		{
			showRoomList();
			super.show(space,onshow);
		}
		
		private function showRoomList():void
		{
			roomList	=	NetSocket.instance.sfx.roomList;
			for each (var tmpRoom:SFSRoom in roomList) 
			{
				
			}
		}
	}
}